package com.project.controller;

import com.github.pagehelper.PageInfo;
import com.project.bean.PostBean;
import com.project.bean.UserBean;
import com.project.service.IPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("post")
public class PostController {
    @Autowired
    private IPostService service;
    @RequestMapping("findByItem")
    public PageInfo<PostBean> findByItem(int channelId, int pageNo,String name, String user,
                                         LocalDateTime startDate,LocalDateTime endDate){
        return service.findByItem(channelId,pageNo,name,user,startDate,endDate);
    }

    @RequestMapping("getPost")
    public List<PostBean> getPost(){
        List<PostBean> list = new ArrayList<>();
        return list;
    }

    @RequestMapping("add")
    public String add(int channelId,String name, String content,String user, HttpServletRequest request){
        UserBean userBean = (UserBean) request.getSession().getAttribute("loginUser");
        user = userBean.getName();
        PostBean post = new PostBean(name,content,channelId,user);

        service.add(post);
        return "ok";
    }
}
